<!DOCTYPE html>
<html lang="en" class="x-admin-sm" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>订单详情</title>

    <header th:replace="header::html"></header>
</head>

<body>

<div class="demoTable">
    <div class="layui-fluid">
        <div class="layui-row  layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body ">
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="startDate" placeholder="请订单生成日期"
                                       name="startDate">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <div class="layui-input-inline">
                                <input type="text" class="layui-input" id="endDate" placeholder="请选择订单结束日期"
                                       name="endDate">
                            </div>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" data-type="reload">搜索</button>

                        </div>
                    </div>
                    <div class="layui-card-body ">
                        <table class="layui-hide" id="orderTable" lay-filter="orderTable"></table>
                    </div>
                    <div class="layui-card-body ">
                        <script type="text/html" id="bar">
                            <a class="layui-btn layui-btn-xs" lay-event="checkDetails">查看详情</a>

                            {{#  if(d.tips1 == "待付款"){ }}
                            <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="pay">确认付款</a>
                            {{#  }else if(d.oendtime <=d.tips3 && d.tips1 == "进行中"){ }}
                            <a class="layui-btn layui-btn-danger layui-btn-xs"
                               lay-event="apply-for-arbitration">申请仲裁</a>

                            {{#  }else if(d.workid!=null && d.tips1 == "已完成" &&d.workid!=""){ }}
                            <a class="layui-btn layui-btn-danger layui-btn-xs"
                               lay-event="dowload" >下载</a>

                            {{#  }

                            else { }}
                            {{#  }}}
                        </script>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>
</body>


<script>

	layui.use('laydate', function () {
		var laydate = layui.laydate;
		//选中后的回调
		laydate.render({
			elem: '#startDate'
			, done: function (value, date) {
			}
		});

		laydate.render({
			elem: '#endDate'
			, done: function (value, date) {
			}
		});

	});

	layui.use('table', function () {
		var table = layui.table;

		//第一个实例
		table.render({
			elem: '#orderTable'
			, url: '/api-front/frontneed/orderList' //数据接口
			, page: true //开启分页
			, limits: [5]
			, limit: 6
			, cols: [
				[ //表头
					{title: 'ID', type: 'numbers', align: 'center', width: '5%'}
					, {field: 'oid', title: '订单ID', align: 'center', hide: true}
					, {field: 'needid', title: '需求ID', align: 'center', hide: true}
					, {field: 'workid', title: '作品ID', align: 'center', hide: true}
					, {field: 'tips3', title: '时间', align: 'center', hide: true}
					, {field: 'tips1', title: '订单状态', align: 'center', width: '13%'}
					, {field: 'tips2', title: '订单金额', align: 'center', width: '13%'}
					, {field: 'ostarttime', title: '订单生成时间', align: 'center', width: '15%'}
					, {field: 'oendtime', title: '结束时间', align: 'center', width: '15%'}
					, {field: 'orealtime', title: '订单工期', align: 'center', width: '11%'}
					, {toolbar: "#bar", title: '操作', width: "25%", align: 'center', width: '28%'}

				]
			]
		});


		table.on('tool(orderTable)', function (obj) {
			//alert(111113);
			var data = obj.data;//获取点击行数据
			if (obj.event === 'checkDetails') {
				//alert("66666");
				var oid2 = data.oid;
				xadmin.open('查看订单详情页面', '/api-front/serviceproviders/orderForm/?oid=' + oid2);


			} else if (obj.event === 'apply-for-arbitration') {
				var oid1 = data.oid;
				layer.prompt({
					formType: 2,
					title: '请输入您申请仲裁的原因(注：必填，不填无法进行操作)'
				}, function (value, index, elem) {
					var msg1 = value.trim();
					if (msg1.length > 0) {
						$.ajax({
							url: "/api-front/arbitration/applyArbitration",
							type: "post",
							data: {orderid: oid1, cause: msg1},
							dataType: 'text',
							success: function (msg) {
								if (msg === "success") {
									layer.alert("申请仲裁成功", {icon: 1}, function (index1) {
										layer.close(index1);
										table.reload('orderTable');
									});
								} else {
									layer.alert("申请仲裁失败", {icon: 1}, function (index1) {
										layer.close(index1);
										table.reload('orderTable');
									});

								}
							}
						});

						layer.close(index);
					} else {
						alert("请输入需要仲裁的原因，再进行操作！");
						// layer.msg('请输入您要充值的金额，再进行操作！', {icon: 2});
					}

				});
			} else if (obj.event === "pay") {

				if (data.workid === 0) {
					var nid1 = data.needid;
					var oid1 = data.oid;
					$.ajax({
						url: "/api-front/frontneed/payMoneyNeed",
						type: "GET",
						data: {nid: nid1, oid: oid1},
						dataType: 'text',
						success: function (msg) {
							if (msg === "yes") {
								layer.alert("付款成功", {icon: 1}, function (index1) {
									layer.close(index1);
									table.reload('orderTable');
								});

							} else {
								layer.alert("付款失败，余额不足", {icon: 1}, function (index1) {
									layer.close(index1);
									table.reload('orderTable');
								});

							}
						}
					});


				}  else {

					var wid = data.workid;
					xadmin.open('作品付款页面', '/api-front/userOrder/?workid=' + wid);
				}
			}else if (obj.event==="dowload"){

				window.location.href="/api-front/purchase/download?wid="+data.workid;
			}
		});


		$('.demoTable .layui-btn').on('click', function () {
			var type = $(this).data('type');
			if (type == 'reload') {
				//执行重载
				table.reload('orderTable', {
					page: {
						curr: 1 //重新从第 1 页开始
					}
					, where: {
						startDate: $("#startDate").val(),
						endDate: $("#endDate").val()
					}
				});
			}


		});


	});


</script>
</html>